#include "StdAfx.h"
#include <stdlib.h>
#include "BlockInterleaver.h"
#include <math.h>

CBlockInterleaver::CBlockInterleaver(uint32_t size)
{
	uint32_t square_size = (uint32_t)sqrt((double)size);
	uint32_t eff_size = square_size*square_size;
	mInterleaveIndex = new uint32_t[eff_size];
	mDeInterleaveIndex = new uint32_t[eff_size];		
	mSize = eff_size;
	if(mInterleaveIndex!=NULL)
	{
		for(uint32_t i=0;i<square_size;i++){
			for(uint32_t j=0;j<square_size;j++){
				mInterleaveIndex[i*square_size+j] = j*square_size+i;
				mDeInterleaveIndex[j*square_size+i] = i*square_size+j;
			}
		}            
	}    		
};